//package com.learn.core.controller.view;
//
//
//import com.alibaba.fastjson.JSONObject;
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.github.pagehelper.Page;
//import com.github.pagehelper.PageHelper;
//import com.learn.common.annotation.UserLoginToken;
//import com.learn.common.enums.ResultEnum;
//import com.learn.common.utils.ResultUtil;
//import com.learn.common.utils.result.CommonResult;
//import com.learn.core.domain.LChapter;
//import com.learn.core.domain.LTheme;
//import com.learn.core.domain.view.ChapterCourseWareLearn;
//import com.learn.core.domain.view.CourseEnroll;
//import com.learn.core.domain.LCourse;
//import com.learn.core.domain.view.UserDetailsGather;
//import com.learn.core.dto.ChapterCourseWareLearnDTO;
//import com.learn.core.dto.CourseChapterDTO;
//import com.learn.core.dto.CourseThemeDTO;
//import com.learn.core.dto.MyLearnDTO;
//import com.learn.core.service.*;
//import com.learn.core.service.IChapterCourseWareLearnService;
//import com.learn.core.service.IUserDetailsGatherService;
//import com.learn.core.vo.CourseCaptherVO;
//import com.learn.core.vo.CourseThemeVO;
//import com.learn.core.vo.MyLearnVO;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//
//import org.apache.commons.lang3.time.DateFormatUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.Date;
//import java.util.List;
//
///**
// * @auther CodeGenerator
// * @create 2021-03-13 19:41:29
// * @describe
// */
//
//@Api("我的学习")
//@RestController
//@RequestMapping("/learn/view")
//public class MyLearnController {
//
//    @Autowired
//    private IUserDetailsGatherService iUserDetailsGatherService;
//
//    @Autowired
//    private ILCourseService ilCourseService;
//
//    @Autowired
//    private ICourseEnrollService iCourseEnrollService;
//
//    @Autowired
//    private ILChapterService ilChapterService;
//
//    @Autowired
//    private ILThemeService ilThemeService;
//
//    @Autowired
//    private IChapterCourseWareLearnService iChapterCourseWareLearnService;
//
//    //列表
//    @ApiOperation(value = "获取个人信息、我课程列表、推荐列表")
//    @UserLoginToken
//    @PostMapping("/mylearn")
//    public CommonResult<Object> myCourseList(@RequestBody MyLearnDTO myLearnDTO){
//
//        try {
//            if(myLearnDTO==null|myLearnDTO.getUserId()==null||myLearnDTO.getPageNo()==null){
//                return  (CommonResult) ResultUtil.error(ResultEnum.LOAD_ERROR);
//            }
//            QueryWrapper<UserDetailsGather> queryWrapper = new QueryWrapper<>();
//            queryWrapper.eq("user_id",myLearnDTO.getUserId());
//            UserDetailsGather userDetailsGather = iUserDetailsGatherService.getOne(queryWrapper);
//            MyLearnVO myLearnVO = new MyLearnVO();
//            myLearnVO.setUserDetailsGather(userDetailsGather);
//
//            QueryWrapper<LCourse> lCourseQueryWrapper = new QueryWrapper<>();
//            lCourseQueryWrapper.last("where recommend_stutes ='1' and release_stutes ='1' and course_fail_time > '"+
//                    DateFormatUtils.format(new Date(),"yyyy-MM-dd") +"' limit 0,5");
//            List<LCourse> lCourses = ilCourseService.list(lCourseQueryWrapper);
//            myLearnVO.setLCourse(lCourses);
//
//            QueryWrapper<CourseEnroll> courseEnrollQueryWrapper = new QueryWrapper<>();
//            courseEnrollQueryWrapper.last("where recommend_stutes ='1' and release_stutes ='1' and user_id = "+
//                    myLearnDTO.getUserId()+" " +
//                    "and course_fail_time > '"+ DateFormatUtils.format(new Date(),"yyyy-MM-dd") +
//                    "' limit "+myLearnDTO.getPageNo()*5+","+(myLearnDTO.getPageNo()+1)*5);
//            List<CourseEnroll> courseEnrollList = iCourseEnrollService.list(courseEnrollQueryWrapper);
//            myLearnVO.setCourseEnroll(courseEnrollList);
//            return (CommonResult)ResultUtil.success(ResultEnum.SUCCESS,myLearnVO);
//        }catch (Exception e){
//            e.printStackTrace();
//            return (CommonResult)ResultUtil.error(ResultEnum.ERROR);
//        }
//    }
//
//
//    //列表
//    @ApiOperation(value = "获取课程信息、章节列表")
//    @UserLoginToken
//    @PostMapping("/coursechapter")
//    public CommonResult<Object> courseChapterlist(@RequestBody CourseChapterDTO courseChapterDTO){
//
//        try {
//            if(courseChapterDTO==null|courseChapterDTO.getCourseId()==null){
//                return  (CommonResult) ResultUtil.error(ResultEnum.LOAD_ERROR);
//            }
//
//            CourseCaptherVO courseCaptherVO = new CourseCaptherVO();
//            QueryWrapper<LChapter>   queryWrapper = new QueryWrapper<>();
//            queryWrapper.eq("chapter_item",0);
//            queryWrapper.orderByDesc("chapter_seq");
//            List<LChapter> lChapters = ilChapterService.list(queryWrapper);
//            JSONObject jsonObject = new JSONObject();
//            if(lChapters!=null){
//                for (LChapter lChapter: lChapters) {
//
//                    queryWrapper = new QueryWrapper<>();
//                    queryWrapper.eq("chapter_item",lChapter.getChapterId());
//                    queryWrapper.orderByDesc("chapter_seq");
//                    List<LChapter> lChapters1 = ilChapterService.list();
//                    jsonObject.put( lChapter.getChapterName(),lChapters1);
//                }
//            }
//            courseCaptherVO.setLChapters(jsonObject);
//
//            courseCaptherVO.setLCourses(ilCourseService.getById(courseChapterDTO.getCourseId()));
//
//            return (CommonResult)ResultUtil.success(ResultEnum.SUCCESS);
//        }catch (Exception e){
//            e.printStackTrace();
//            return (CommonResult)ResultUtil.error(ResultEnum.ERROR);
//        }
//    }
//
//    //列表
//    @ApiOperation(value = "获取主题信息、课程列表")
//    @UserLoginToken
//    @PostMapping("/coursetheme")
//    public CommonResult<Object> courseThemeList(@RequestBody CourseThemeDTO courseThemeDTO){
//
//        try {
//            if(courseThemeDTO==null){
//                return  (CommonResult) ResultUtil.error(ResultEnum.LOAD_ERROR);
//            }
//
//            CourseThemeVO courseThemeVO = new CourseThemeVO();
//            QueryWrapper<LTheme>   queryWrapper = new QueryWrapper<>();
//            if(courseThemeDTO.getThemeId()==null)
//                queryWrapper.eq("parent_node",0);
//            else
//                queryWrapper.eq("theme_id",courseThemeDTO.getThemeId());
//
//            queryWrapper.orderByDesc("theme_id");
//            List<LTheme> lThemes = ilThemeService.list(queryWrapper);
//            JSONObject jsonObject = new JSONObject();
//            if(lThemes!=null){
//                for (LTheme lTheme: lThemes) {
//
//                    queryWrapper = new QueryWrapper<>();
//                    queryWrapper.eq("parent_node",lTheme.getThemeId());
//                    queryWrapper.orderByDesc("theme_id");
//                    List<LTheme> lChapters1 = ilThemeService.list(queryWrapper);
//                    jsonObject.put(lTheme.getThemeName(),lChapters1);
//                }
//            }
//            courseThemeVO.setTheme(jsonObject);
//            QueryWrapper<LCourse>   queryWrapper1 = new QueryWrapper<>();
//            String lastSql = "";
//            if(courseThemeDTO.getThemeId()==null) {
//
//                lastSql += "where recommend_stutes ='1' and release_stutes ='1' and course_fail_time > '"+ DateFormatUtils.format(new Date()
//                ,"yyyy-MM-dd") +"'";
//            }else{
//                lastSql += "where ( course_theme ="+courseThemeDTO.getThemeId()+" or course_theme_flt = "+courseThemeDTO.getThemeId()+" ) and " +
//                        "recommend_stutes ='1' and release_stutes ='1' and course_fail_time > '"+ DateFormatUtils.format(new Date()
//                        ,"yyyy-MM-dd") +"'";
//            }
//            if(courseThemeDTO.getPageNo()!=null&&courseThemeDTO.getRows()!=null){
//                PageHelper.startPage(courseThemeDTO.getPageNo(),courseThemeDTO.getRows());
//            }else{
//                PageHelper.startPage(0,10);
//            }
//            queryWrapper1.last(lastSql);
//
//            Page<LCourse> lCourses = (Page<LCourse>) ilCourseService.list(queryWrapper1);
//            courseThemeVO.setLCourses(lCourses);
//            return (CommonResult)ResultUtil.success(ResultEnum.SUCCESS,courseThemeVO);
//        }catch (Exception e){
//            e.printStackTrace();
//            return (CommonResult)ResultUtil.error(ResultEnum.ERROR);
//        }
//    }
//
//    //列表
//    @ApiOperation(value = "获取播放视频")
//    @UserLoginToken
//    @PostMapping("/coursevod")
//    public CommonResult<Object> courseThemeList(@RequestBody ChapterCourseWareLearnDTO chapterCourseWareLearnDTO){
//
//        try {
//            if(chapterCourseWareLearnDTO==null){
//                return  (CommonResult) ResultUtil.error(ResultEnum.LOAD_ERROR);
//            }
//            if(chapterCourseWareLearnDTO.getCourseId()==null){
//                return  (CommonResult) ResultUtil.error(ResultEnum.NOT_CHA_COURSE);
//            }
//            if(chapterCourseWareLearnDTO.getCourseId()==null){
//                return  (CommonResult) ResultUtil.error(ResultEnum.NOT_CHA_USER);
//            }
//
//            QueryWrapper<ChapterCourseWareLearn> queryWrapper = new QueryWrapper<>();
//            queryWrapper.last("where (user_id = "+chapterCourseWareLearnDTO.getUserId()+" or " +
//                    "user_id is null ) and "+
//                    " course_id = "+chapterCourseWareLearnDTO.getCourseId());
//
//            List<ChapterCourseWareLearn> learns = iChapterCourseWareLearnService.list(queryWrapper);
//
//            return (CommonResult)ResultUtil.success(ResultEnum.SUCCESS,learns);
//        }catch (Exception e){
//            e.printStackTrace();
//            return (CommonResult)ResultUtil.error(ResultEnum.ERROR);
//        }
//    }
//
//
//
//}
//
